home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5704 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Initialising structure members - help please!
  5. Date: Tue, 20 Feb 96 22:04:56 GMT
  6. Organization: none
  7. Message-ID: <824853896snz@genesis.demon.co.uk>
  8. References: <4gb8hn$3m8@news.mistral.co.uk> <31298EF1.5F2C@cmt.lpr.mail.carel.fi> <4gckb1$77e@news.mistral.co.uk>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4gckb1$77e@news.mistral.co.uk>
  15.            mikebarnard@mistral.co.uk "Mike Barnard" writes:
  16.  
  17. >Thanks, I'll look at what this means. But as a learning question, (not
  18. >an argumentative one!!!),  why does this good old boy work then?
  19. >
  20. >char name[]="An array of characters";
  21.  
  22. This can also be written as:
  23.  
  24. char name[]= { "An array of characters" };
  25.  
  26. C permits this as a special case for character array initialisation. Note
  27. the word 'initialisation' - this isn't an assignment. It is equivalent to:
  28.  
  29.  char name[] = {
  30.       'A', 'n', ' ', 'a', 'r', 'r', 'a', 'y', ' ', 'o', 'f', ' ',
  31.       'c', 'h', 'a', 'r', 'a', 'c', 't', 'e', 'r', 's', '\0'
  32.  };
  33.  
  34. >Surely "name" is an array of characters as is my "description"? It
  35. >works here. Doesn't it? This leads me on to another question actually,
  36.  
  37. You can initialise arrays when you define them, but you can't assign to
  38. them afterwards (just to their elements where appropriate).
  39.  
  40. -- 
  41. -----------------------------------------
  42. Lawrence Kirby | fred@genesis.demon.co.uk
  43. Wilts, England | 70734.126@compuserve.com
  44. -----------------------------------------
  45.